package com.hcb.tonguetiphealth.manager;

import java.io.InputStream;
import java.net.URL;

import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.text.Spanned;
import android.widget.TextView;

public class TextViewShowHtmlManager {  
    public static void show(final TextView text, final String html) {
    	final Handler mHandler = new Handler() {
			public void handleMessage(Message msg) {
				text.setText((Spanned) msg.obj);
			}
		};
    	new Thread() {
			public void run() {
				Spanned sp = Html.fromHtml(html, new Html.ImageGetter() {
					@Override
					public Drawable getDrawable(String source) {
						InputStream is = null;
						try {
							is = (InputStream) new URL(source).getContent();
							Drawable d = Drawable.createFromStream(is, "src");
//							d.setBounds(0, 0, d.getIntrinsicWidth(),
//									d.getIntrinsicHeight());
							d.setBounds(0, 0, 250,//图片宽度、高度设置
									150);
							is.close();
							return d;
						} catch (Exception e) {
							return null;
						}
					}
				}, null);
				Message msg = mHandler.obtainMessage(0, sp);  
				mHandler.sendMessage(msg);
			}
		}.start();
    }
}
